package Offer500;

import java.util.ArrayList;
import java.util.List;

/**
 * . 键盘行
 * 给你一个字符串数组 words ，只返回可以使用在 美式键盘 同一行的字母打印出来的单词。键盘如下图所示。
 */
public class Test {
    public static void main(String[] args) {

    }
}

class Solution {
    public String[] findWords(String[] words) {
        String s1 = "qwertyuiopQWERTYUIOP";
        String s2 = "asdfghjklASDFGHJKL";
        String s3 = "zxcvbnmZXCVBNM";
        List<String> list = new ArrayList<>();
        for(String  word : words){
            int n1 = 0, n2 = 0 , n3 = 0 ,leng = word.length();
            for(int i = 0 ; i < leng ; i++){
                if(s1.contains(word.charAt(i)+"")) n1++;
                else if(s2.contains(word.charAt(i)+"")) n2++;
                else  n3++;
            }
            if(n1 == leng || n2 == leng || n3 == leng) list.add(word);
        }
        return list.toArray(new String[list.size()]);
    }
}
